package pl.edu.agh.io.gpstracker.server.service.handler;

import net.customware.gwt.dispatch.server.ActionHandlerRegistry;
import net.customware.gwt.dispatch.server.ExecutionContext;
import net.customware.gwt.dispatch.shared.ActionException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import pl.edu.agh.io.gpstracker.client.action.AddNewTrackAction;
import pl.edu.agh.io.gpstracker.client.action.DeleteUserAction;
import pl.edu.agh.io.gpstracker.client.result.VoidResult;
import pl.edu.agh.io.gpstracker.service.TrackService;
import pl.edu.agh.io.gpstracker.service.UserService;

import com.adeoservices.gwt.dispatch.spring.server.handler.SpringActionHandler;

/**
 * 
 * @author wkedzior
 * 
 */
@Component
public class FindTrackByUser extends
		SpringActionHandler<AddNewTrackAction, VoidResult> {

	@Autowired
	private TrackService trackService;

	@Autowired
	public FindTrackByUser(ActionHandlerRegistry actionHandlerRegistry) {
		super(actionHandlerRegistry);
	}

	@Override
	public Class<AddNewTrackAction> getActionType() {
		return AddNewTrackAction.class;
	}

	@Override
	public VoidResult execute(AddNewTrackAction action, ExecutionContext context) {
		trackService.saveOrUpdateTrack(action.getTrack());
		return null;
	}

	@Override
	public void rollback(AddNewTrackAction action, VoidResult result,
			ExecutionContext context) throws ActionException {
		// TODO Auto-generated method stub

	}
}
